﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

namespace Wimm.Common.Converters
{
    public class StringToVisibilityConverter : IValueConverter
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter">reverse converter value if true</param>
        /// <param name="language"></param>
        /// <returns><see cref="Visibility"/></returns>
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            try
            {
                bool reverse = false;
                if (parameter != null && bool.TryParse((string)parameter, out reverse))// && bool.TryParse((string)parameter, out reverse))
                {
                    //reverse = true;
                }
                string v = (string)value;
                bool visible = reverse ? !string.IsNullOrEmpty(v) : string.IsNullOrEmpty(v); //!string.IsNullOrEmpty(v);//

                return visible ? Visibility.Visible : Visibility.Collapsed;
            }
            catch
            {
                return Visibility.Collapsed;
            }
        }
        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
}